#include "eventmanager.h"

using namespace mlgesture;
using namespace std;

EventManager& EventManager::getInstance() {
	static EventManager instance;
	return instance;
}

void EventManager::addObserver(GestureObserver *observer) {
	for (vector<GestureObserver*>::iterator it = observers_.begin(); it != observers_.end(); ++it) {
		if (*it == observer) return;
	}
	observers_.push_back(observer);
}

void EventManager::removeObserver(GestureObserver *observer) {
	for (vector<GestureObserver*>::iterator it = observers_.begin(); it != observers_.end(); ++it) {
		if (*it == observer) {
			observers_.erase(it);
			break;
		}
	}
}

void EventManager::sendEvent(GestureEvent *event) {
	for (vector<GestureObserver*>::iterator it = observers_.begin(); it != observers_.end(); ++it) {
		(*it)->processEvent(event);
	}
}
